package com.common.springbootcommonmessage.enums;

import java.util.HashMap;

public enum AdminRange {
    SuperAdmin(0), Admin(1), Vendor(2), OtherVendor(3);

    private final int value;
    private static HashMap<Integer, AdminRange> integerMap = new HashMap<Integer, AdminRange>();
    private static HashMap<String, Integer> roleMap = new HashMap<>();

    AdminRange(Integer value) {
        this.value = value;
    }

    static {
        for (AdminRange status : AdminRange.values()) {
            integerMap.put(status.getValue(), status);
            roleMap.put(status.name(), status.getValue());
        }
    }

    public Integer getValue() {
        return this.value;
    }

    public static AdminRange valueOf(Integer value) {
        return (AdminRange) integerMap.get(value);
    }

    public static Integer getRoleByName(String name) {
        return (Integer)roleMap.get(name);
    }


    /*
    *  根据等级的值返回等级编码
    * */
    public static String getRangeCode(Integer value){

        if(value==null) return null;

        if(integerMap.containsKey(value)){
            return integerMap.get(value).name();
        }else{
            return null;
        }
    }
}